package cn.zzf.algs.note.base.collection.v1;

/**
 * @author GaoFeng
 * @date 2019/11/28 9:22
 */
public class Node<T> {

    /** 节点值 */
    T value;

    /** 链表下一个节点 */
    Node<T> next;

    public Node(T value, Node<T> node) {
        this.value = value;
        this.next = node;
    }

    @Override
    public String toString() {
        return "Node{" +
                "value=" + value +
                ", next=" + next +
                '}';
    }

    public String toFormatString() {
        StringBuilder result = new StringBuilder();
        Node<T> currentNode = this;
        result.append("[");
        while (currentNode != null) {
            result.append(currentNode.value).append(", ");
            currentNode = currentNode.next;
        }

        result.delete(result.length() - 2, result.length());
        result.append("]");

        return result.toString();
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public Node<T> getNext() {
        return next;
    }

    public void setNext(Node<T> next) {
        this.next = next;
    }



}
